package com.sansi.bleFloodlight.adapter;

import android.text.TextUtils;
import android.view.View;

import com.a1anwang.okble.client.scan.BLEScanResult;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sansi.bleFloodlight.R;

import java.util.List;

public class SearchLightResultAdapter extends BaseQuickAdapter<BLEScanResult, BaseViewHolder> {

    private List<Boolean> selectList;

    public SearchLightResultAdapter() {
        super(R.layout.layout_item_search_light);
    }

    @Override
    protected void convert(final BaseViewHolder helper, BLEScanResult myDevice) {
        helper.setText(R.id.tv_bledevice_name, TextUtils.isEmpty(myDevice.getBluetoothDevice().getName()) ?
                "SanSi_" + myDevice.getBluetoothDevice().getAddress() : myDevice.getBluetoothDevice().getName() +
                "_" + myDevice.getBluetoothDevice().getAddress());
        boolean isSelectList = selectList.get(helper.getLayoutPosition());
        if (isSelectList) {
            helper.setImageResource(R.id.iv_select, R.drawable.select_s);
        } else {
            helper.setImageResource(R.id.iv_select, R.drawable.select_n);
        }
    }

    public void setNewData(List<BLEScanResult> listData, List<Boolean> selectList) {
        this.selectList = selectList;
        super.setNewData(listData);
    }
}
